package com.shunwang.caipiao.data.schedule;

import java.io.IOException;
import java.util.List;

import com.shunwang.caipiao.data.bo.CaiPiaoBo;
import com.shunwang.caipiao.data.pojo.DoubleColor;
import com.shunwang.htmlparser.controller.SimpleController;

public class SimpleDateSyncSchedule {

	private CaiPiaoBo caiPiaoBo;
	private SimpleController controller;
	private final String url ="http://fcasp.zjol.com.cn/zjfc/asp_ssq.asp?pagenum=";
	
	public void sync() throws IOException{
		List<DoubleColor> list;
		for(int i=49;i>0;i--){
			String uri = url+i;
			list = controller.getDoubleColor(uri);
			if(list != null && list.size() > 0){
				for(DoubleColor color:list){
					if(!caiPiaoBo.checkSnoExists(color.getSno())){
						caiPiaoBo.saveDoubleColor(color);
					}
				}
			}
		}
	}
	
	public void syncNew() throws IOException{
		List<DoubleColor> list = controller.getDoubleColor(url+1);
		if(list != null && list.size() > 0){
			for(DoubleColor color:list){
				if(!caiPiaoBo.checkSnoExists(color.getSno())){
					caiPiaoBo.saveDoubleColor(color);
				}
			}
		}
	}
	public SimpleController getController() {
		return controller;
	}

	public void setController(SimpleController controller) {
		this.controller = controller;
	}

	public CaiPiaoBo getCaiPiaoBo() {
		return caiPiaoBo;
	}

	public void setCaiPiaoBo(CaiPiaoBo caiPiaoBo) {
		this.caiPiaoBo = caiPiaoBo;
	}
	
	
}
